Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

495
Visualizações
Node Fetch blobFromSync and blobFrom TypeError [ERR_INVALID_URL]: Invalid URL

I am trying to read a file that is local to my computer into a blob using the node-fetch library, but each time I do, I get this Invalid Url Error. My code is the following:

const express = require('express');
const cors = require('cors');
const bodyParser = require("body-parser");


const fetch = (...args) =>
  import('node-fetch').then(({ default: fetch }) => fetch(...args));

const blobFromSync = (...args) =>
  import('node-fetch').then(({ blobFromSync }) => fetch(...args));

  const blobFrom = (...args) =>
  import('node-fetch').then(({ blobFrom }) => fetch(...args));

  const fileFrom = (...args) =>
  import('node-fetch').then(({ fileFrom }) => fetch(...args));



const app = express();
const port = 3000;

//Here we are configuring express to use body-parser as middle-ware.
app.use(cors())
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

app.use(function (req, res, next) {
    res.header("Access-Control-Allow-Origin", "*")
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
    next()
});


app.get('/recorded', async (req, res) => {

    try {
   
        let file_location = './path/to/video.mp4';

        const file = fileFrom(file_location);

        const chunkSize = 40000

        for (let start = 0; start < file.size; start += chunkSize) {
            const chunk = file.slice(start, start + chunkSize + 1)
            //Will eventuay doa fetch
            //await fetch(url, { method: 'post', body: chunk, headers: headers, }).then(res => res.text())
        }

        res.status(200);
        res.send().end();
    } catch (e) {
        console.log(e);
    }
});


app.listen(port, () => {
    console.log(`Example app listening on port ${port}`)
});

The error is the following (its also uncatchable):

TypeError [ERR_INVALID_URL]: Invalid URL
    at new NodeError (node:internal/errors:377:5)
    at URL.onParseError (node:internal/url:563:9)
    at new URL (node:internal/url:643:5)
    at new Request (file:///Users/xxxxxx/Development/terminal-backend/node_modules/node-fetch/src/request.js:55:16)
    at file:///Users/xxxx/Development/terminal-backend/node_modules/node-fetch/src/index.js:51:19
    at new Promise (<anonymous>)
    at fetch (file:///Users/xxxx/Development/terminal-backend/node_modules/node-fetch/src/index.js:49:9)
    at /Users/xxxxx/Development/terminal-backend/src/server.js:11:53 {
  input: './path/to/video.mp4',
  code: 'ERR_INVALID_URL'
}

blobFromSync and blobFrom also throw the same error. If this is a local file, why am I get invalid url?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda